<template>
  <el-drawer
    v-model="complate_box"
    direction="rtl"
    size="80%"
    destroy-on-close
    :close-on-click-modal="false"
    @close="$emit('close')"
  >
    <template #title><h4>项目完成</h4></template>
    <template #default>
      <div class="flex_start">
        <span>完成文件：</span>
        <taskFile :item_form_data="item_form_data" :isAdd="true" :type="4"></taskFile>
      </div>
      <div class="tr m_top10">
        <el-button @click="cancel">取消</el-button>
        <el-button type="primary" @click="submit">确定</el-button>
      </div>
    </template>
  </el-drawer>
</template>

<script lang="ts" setup>
import { ref, toRefs, watch, computed } from "vue";
import axios from "@/service/HttpRequest";
import taskFile from "./taskFile.vue";
import serviceApi from "@/service/api";
import EventBus from "@/utils/EventBus";
import { ElMessage, ElMessageBox } from "element-plus";
const props = defineProps({
  complate_box: Boolean,
  item_form_data: Object,
});
const uploadFile = ref();
EventBus.on("uploadFile", (e: any) => {
  //   console.log(e);
  uploadFile.value = e[0];
});
const { item_form_data, complate_box } = toRefs<any>(props);
const submit = () => {
  ElMessageBox.confirm("确定完成该项目？", "", {
    closeOnClickModal: false,
    type: "warning",
  })
    .then(() => {
      let data = {
        taskId: item_form_data.value.id,
        nodeConfigFileVOList: [],
      };
      (uploadFile.value as any).file_data.forEach((i) => {
        let obj = {
          fileConfigId: i.id,
          fileName: i.fileName.length ? i.fileName.toString() : "",
          fileUrl: i.url.length ? i.url.toString() : "",
        };
        data.nodeConfigFileVOList.push(obj);
      });
      console.log(data);
      axios
        .request({
          url: serviceApi.task_curd + "/finish",
          method: "post",
          data: data,
        })
        .then(() => {
          ElMessage.success("操作成功！");
          setTimeout(() => {
            EventBus.emit("close_box");
          }, 1000);
        })
        .catch((err) => {
          ElMessage.error(err);
        });
    })
    .catch(() => {});
};
const cancel = () => {
  EventBus.emit("close_box");
};
</script>

<style lang="scss" scoped></style>
